﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Megaplan.API.Extentions
{
    public static class ExtensionMethods
    {
        public static string GetQueryString(this object obj, string formatter = null)
        {
            if (String.IsNullOrWhiteSpace(formatter))
                formatter = "{0}={1}";

            var properties = from p in obj.GetType().GetProperties()
                             where p.GetValue(obj, null) != null
                             select String.Format(formatter, p.Name, HttpUtility.UrlEncode(p.GetValue(obj, null).ToString()));

            return String.Join("&", properties.ToArray());
        }
    }
}
